<template>
	<view>
		<navbar name="添加新设备"></navbar>
		<view class="search-view">
			<image class="search-image"
				src="http://static.bsyjk.cn/instrumentsc/DEBD72C434C448F4809DBB1B9FCAA4A1.gif" mode="搜索"></image>
			正在搜索
		</view>
		<scale v-if="equipmentName == '体脂称'" @equipment="equipment"></scale>
		<bloodPressure  v-if="equipmentName == '血压计'" @bloodPressureData="bloodPressureData"></bloodPressure>
	</view>
</template>

<script>
	import scale from "./scale.vue"
	import bloodPressure from "./bloodPressure.vue"
	export default {
		components: {
			scale,
			bloodPressure
		},
		data() {
			return {
				equipmentData:'',//设备回调数组
				facilityList: [{
					title: '体脂称'
				}],
				equipmentIcon:'',
				equipmentName:'',
				remark:'',
				equipmentId:'',
			}
		},
		onLoad(e) {
			console.log(e,40000000)
			this.equipmentIcon = e.equipmentIcon;//图标
			this.equipmentName = e.equipmentName;//设备昵称
			this.remark = e.remark;//设备标签
			this.equipmentId = e.equipmentId;//设备标签
		},
		methods: {
			bloodPressureData(data,index){//血压计
				this.tbEquipmentUser(data,index)
			},
			equipment(data,index) {//体脂称
				this.tbEquipmentUser(data,index)
			},
			// 请求存设备id
			tbEquipmentUser(item, index) {
				let _this = this;
				let fdata = {
					equipmentId:this.equipmentId,
					deviceId:item.deviceId,
					equipmentIcon:this.equipmentIcon,//icon 图标
					equipmentName:this.equipmentName,//昵称
					remark:this.remark,//标签
					mac: item.mac, //mac地址
					userId: uni.getStorageSync(global.IS_DEV?'USER_DATA_BSY_T':'USER_DATA_BSY_Z').userId,
					equipmentTypeId:this.equipmentName=='体脂秤'?1:2
				}
				console.log(fdata,'61111111111111111111111')
				this.$api.post(global.apiUrls.tbEquipmentUser, fdata)
					.then(res => {
						if (res.data.code == 1000) {
							uni.showToast({
								title: '绑定完成',
								duration: 2000
							});
							setTimeout(() => {
								uni.navigateBack({
									delta: 2
								});
							}, 2000);
						}else{
							uni.showToast({
								title: res.data.message,
								icon:'none',
								duration: 2000
							});
						}
					}).catch(err => {})
			},
		}
	}
</script>

<style lang="scss">
	.search-view {
		text-align: center;
		font-size: 36upx;
		font-weight: 400;
		color: #9B9B9B;
		line-height: 50px;

		.search-image {
			width: 400upx;
			height: 400upx;
			display: block;
			// background: pink;
			margin: 200upx auto 10upx;
		}
	}

	.popup-box {
		width: 750upx;
		height: 350upx;
		position: fixed;
		bottom: 0;

		// background: #fff;
		.facility-bg {
			width: 702upx;
			height: 134upx;
			line-height: 70upx;
			background: url(http://static.bsyjk.cn/facilitybg/7FA82009DFA44A5EB0ECBB5BB5E95033.png)no-repeat;
			background-size: 702upx 134upx;
			display: flex;
			padding: 36upx 25upx;
			font-size: 36upx;
			font-weight: 500;
			color: #2EA7E0;
			margin: 0 auto 30upx;

			.bluetooth {
				width: 44upx;
				height: 66upx;
				background: url(http://static.bsyjk.cn/bluetoothicon/2DAB7A96C80D4CADB4C8BAF95D1FA0D5.png)no-repeat;
				background-size: 44upx 66upx;
				margin-right: 30upx;
			}

			.facility-btn {
				width: 136upx;
				height: 46upx;
				background: #2EA7E0;
				border-radius: 42upx;
				font-size: 24upx;
				font-weight: 500;
				color: #FFFFFF;
				line-height: 46upx;
				padding: 0;
				margin-top: 14upx;
			}
		}
	}
</style>
